import Common from "./Common";
import GameUI from "./GameUI";

export default class boxCollider extends Laya.Script {
    /** @prop {name:intType, tips:"整数类型示例", type:Int, default:1000}*/
    public intType: number = 1000;
    /** @prop {name:numType, tips:"数字类型示例", type:Number, default:1000}*/
    public numType: number = 1000;
    /** @prop {name:strType, tips:"字符串类型示例", type:String, default:"hello laya"}*/
    public strType: string = "hello laya";
    /** @prop {name:boolType, tips:"布尔类型示例", type:Bool, default:true}*/
    public boolType: boolean = true;
    // 更多参数说明请访问: https://ldc2.layabox.com/doc/?nav=zh-as-2-4-0
    issucced = false;
    constructor() { super(); }
    onEnable(): void {

    }
    onTriggerEnter(other: any, self: any, contact: any) {
        console.log("碰撞", other.owner);
        Common.isMove = false;
        let otherImage = other.owner as Laya.Image;
        this.owner.addChild(other.owner);
        this.owner.setChildIndex(other.owner, 0);
        switch (Common.type) {
            case 1:
                (other.owner as Laya.Image).pos(-10, 30);
                break;
            case 2:
                (other.owner as Laya.Image).pos(-2, 30);
                break;
        }
        Laya.Tween.to(this.owner.parent.getChildByName("rope"), { height: 5 }, 500);
        Laya.Tween.to(this.owner, { y: 94 }, 500);
        (other.owner as Laya.Image).getComponent(Laya.RigidBody).destroy();
        (other.owner as Laya.Image).getComponent(Laya.CircleCollider).destroy();
        this.owner.getComponent(Laya.RigidBody).destroy();
        this.owner.getComponent(Laya.BoxCollider).destroy();
        switch (Common.type) {
            case 1:
                Laya.timer.once(600, this, () => {
                    Laya.Tween.to(this.owner.parent, { x: 156 }, 500, null, Laya.Handler.create(this, () => {
                        Laya.Tween.to(otherImage, { y: otherImage.y + 150, alpha: 0 }, 500, null, Laya.Handler.create(this, () => {
                            otherImage.alpha = 1;
                            otherImage.y = 420;
                            (this.owner.parent.parent.getChildByName("timeDown") as Laya.Image).visible = false;
                            if (Common.istaobao) {
                                $global.gameOver();
                            }
                            // Laya.timer.once(2000,this,()=>{
                            //     Laya.Scene.open("OneScene.scene");
                            // })
                        }));
                    }))
                })
                break;
            case 2:
                Laya.timer.once(600, this, () => {
                    Laya.Tween.to(this.owner.parent, { x: -88 }, 500, null, Laya.Handler.create(this, () => {
                        Laya.Tween.to(otherImage, { y: otherImage.y + 150, alpha: 0 }, 500, null, Laya.Handler.create(this, () => {
                            this.owner.parent.parent.parent.getChildByName("qius").addChild(otherImage);
                            otherImage.alpha = 1;
                            otherImage.x = 245.5;
                            otherImage.y = 1160;
                            (this.owner.parent.parent.parent.getChildByName("timeDown") as Laya.Image).visible = false;
                            if (Common.istaobao) {
                                $global.gameOver();
                            }
                            // Laya.timer.once(2000,this,()=>{
                            //     Laya.Scene.open("OneScene.scene");
                            // })
                        }));
                    }))
                })
                break;
        }

    }

    onDisable(): void {
    }
}